package com.three.iot.channel.impl.chinamobile;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.iot.model.v20180120.QueryDeviceRequest;
import com.aliyuncs.iot.model.v20180120.QueryDeviceResponse;
import com.aliyuncs.iot.model.v20180120.SetDevicePropertyRequest;
import com.aliyuncs.iot.model.v20180120.SetDevicePropertyResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

/**
 * @author luiz
 * @Title: IotTest
 * @ProjectName iot-server
 * @Description: TODO
 * @date 2019-05-07 13:02
 */
public class QueryDeviceListTest {
    public static void main(String[] args) {
        // 阿里云accessKey
        String accessKey = "LTAIM4zSiZd7rMzu";
        // 阿里云accessSecret
        String accessSecret = "LiKB95DldnjMSGhzrUIcFEqmysb864";
        try {
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com");
        } catch (ClientException e) {
            e.printStackTrace();
        }
        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
        //初始化SDK客户端
        DefaultAcsClient client = new DefaultAcsClient(profile);

        QueryDeviceRequest request = new QueryDeviceRequest();
        request.setProductKey("a1BIyMhGr5p");
        try {
            System.err.println("【阿里云】查询设备列表请求参数:" + JSONObject.toJSONString(request));
            QueryDeviceResponse response = client.getAcsResponse(request);
            System.err.println("【阿里云】查询设备列表响应数据:" + JSONObject.toJSONString(response));
            /*if (response.getSuccess()) {
                SetDevicePropertyResponse.Data devicePropertyRespData = response.getData();
                String messageId = devicePropertyRespData.getMessageId();
                System.err.println(messageId);
            }*/
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
